package com.lex.crossgate.admin.modules.sys.service.imp;

import com.lex.crossgate.common.constants.Constant;
import com.lex.crossgate.common.constants.R;;
import com.lex.crossgate.admin.modules.sys.dao.SysOrgDao;
import com.lex.crossgate.admin.modules.sys.entity.SysOrg;
import com.lex.crossgate.admin.modules.sys.service.SysOrgService;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * java类简单作用描述
 *
 * @ProjectName: crossgate
 * @Package: com.lex.crossgate.admin.modules.sys.service.imp
 * @ClassName: ${TYPE_NAME}
 * @Description: java类作用描述
 * @Author: 李贝留斯
 * @CreateDate: 2018/5/2 15:55
 * @Version: 1.0
 **/
@Service("sysOrgService")
public class SysOrgServiceImpl implements SysOrgService {

    @Autowired
    private SysOrgDao sysOrgDao;

    /**
     * @description: 保存用户
     * @author 李贝留斯
     * @email sunyadongsyd@163.com
     * @date 2018/5/10 22:45
     */
    public R save(SysOrg sysOrg) {
        int row = sysOrgDao.insert(sysOrg);
        if(row>0){
           return R.ok(Constant.SUCCESS);
        }else {
            return R.error(Constant.ERROR);
        }
    }

    @Override
    public R delete(String ids) {
        String[] id = ids.split(",");
        for(int i=0;i<id.length;i++){
            sysOrgDao.deleteById(id[i]);
        }
        return R.ok(Constant.SUCCESS);
    }

    @Override
    public R update(SysOrg SysOrg) {
        int row = sysOrgDao.updateById(SysOrg);
        if(row>0){
            return R.ok(Constant.SUCCESS);
        }else {
            return R.error(Constant.ERROR);
        }
    }

    @Override
    public List<SysOrg> getSysOrg() {
        EntityWrapper entityWrapper = new EntityWrapper();
        return sysOrgDao.selectList(entityWrapper);
    }
    @Override
    public List<SysOrg> getSysOrg(String name,String code) {
        EntityWrapper entityWrapper = new EntityWrapper();
        if(StringUtils.isNotEmpty(name))
            entityWrapper.like("name",name);
        if(StringUtils.isNotEmpty(code))
            entityWrapper.like("code",code);
        return sysOrgDao.selectList(entityWrapper);
    }

    @Override
    public SysOrg getOrgById(String id) {
        SysOrg SysRole = sysOrgDao.selectById(id);
        return SysRole;
    }

}
